package com.dengpp.pdform.config;

import java.io.Serializable;
import java.util.List;

public class FormConfig implements Serializable {
    private String title;
    private List<AttributeConfig> attributes;
    private boolean editMode;
    private String submitButtonText;
    private String cancelButtonText;

    public FormConfig(String title, List<AttributeConfig> attributes) {
        this.title = title;
        this.attributes = attributes;
        this.editMode = true;
        this.submitButtonText = "保存";
        this.cancelButtonText = "取消";
    }
    /**
     * 在反序列化后恢复数据
     */
    public void restoreAfterSerialization() {
        if (attributes != null) {
            for (AttributeConfig attribute : attributes) {
                attribute.restoreAfterSerialization();
            }
        }
    }
    // Builder 模式方法
    public FormConfig setEditMode(boolean editMode) {
        this.editMode = editMode;
        return this;
    }

    public FormConfig setSubmitButtonText(String submitButtonText) {
        this.submitButtonText = submitButtonText;
        return this;
    }

    public FormConfig setCancelButtonText(String cancelButtonText) {
        this.cancelButtonText = cancelButtonText;
        return this;
    }

    // Getters
    public String getTitle() { return title; }
    public List<AttributeConfig> getAttributes() { return attributes; }
    public boolean isEditMode() { return editMode; }
    public String getSubmitButtonText() { return submitButtonText; }
    public String getCancelButtonText() { return cancelButtonText; }
}